package com.smart.manager.member.repository;

import cn.hutool.core.lang.Opt;
import com.smart.common.entities.core.Page;
import com.smart.manager.member.entities.bodys.RMemberPigSaleBill;
import com.smart.manager.member.entities.models.MemberPigSaleBill;
import com.smart.manager.member.entities.models.query.QMemberPigSaleBill;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;


/**
 * 售卖流水
 *
 * @author leo
 * @date 2023/09/22
 */
@Service
@Log4j2
@RequiredArgsConstructor
public class MemberPigSaleBillRepository {


    public Page<MemberPigSaleBill> pageList(RMemberPigSaleBill.SearchBody search) {
        QMemberPigSaleBill query = new QMemberPigSaleBill();
        Opt.ofBlankAble(search.getMemberId()).ifPresent(x -> query.memberId.eq(x));
        Opt.ofBlankAble(search.getPigId().getCode()).ifPresent(x -> query.pigId.code.contains(x));
        query.order().id.desc();
        query.setFirstRow(search.firstRow()).setMaxRows(search.maxRows());
        return new Page<MemberPigSaleBill>().load(query.findPagedList());
    }
    
}
